from rest_framework import serializers

from goods.models import SPU, Brand, GoodsCategory


class SPUSerializer(serializers.ModelSerializer):
    brand = serializers.CharField(read_only=True)
    brand_id = serializers.IntegerField()

    # 一级  模型类中没有 自定义主要用于给前端做显示
    category1_id = serializers.IntegerField()
    category1 = serializers.CharField(read_only=True)
    #
    # # 二级
    category2_id = serializers.IntegerField()
    category2 = serializers.CharField(read_only=True)
    #
    # # 三级
    category3_id = serializers.IntegerField()
    category3 = serializers.CharField(read_only=True)

    class Meta:
        model = SPU
        fields = "__all__"


# 新增SKU品牌信息
class GoodsBrandSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = ['id', 'name']


# 新增SKU分类信息
class GoodCategorySerialier(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = ['id', 'name']
